#include "TableScene.h"

cocos2d::Scene* TableScene::createScene()
{
	return TableScene::create();
}

bool TableScene::init()
{
	if (!Scene::init())
	{
		return false;
	}

	//创建表格
	Size visibilitySize = Director::getInstance()->getVisibleSize();

	TableView* tableView = TableView::create(this, visibilitySize);

	addChild(tableView);
	return true;
}

ssize_t TableScene::numberOfCellsInTableView(TableView *table)
{
	return 10;
}

cocos2d::Size TableScene::tableCellSizeForIndex(TableView* table, ssize_t idx)
{
	return Size(200, 181);
}

cocos2d::extension::TableViewCell* TableScene::tableCellAtIndex(TableView *table, ssize_t idx)
{
	//cell复用机制
	TableViewCell* cell = table->dequeueCell();
	if (!cell)
	{
		cell = TableViewCell::create();
	}
	cell->removeAllChildrenWithCleanup(true);
	//可以开始布局cell的内容了
	Label* label = Label::createWithTTF(StringUtils::format("cell: %lu", idx), "fj3.ttf", 40);
	label->setPosition(Vec2(300, 90));

	Sprite* sprite = Sprite::create("men.jpg");
	sprite->setScale(0.5);
	sprite->setAnchorPoint(Vec2::ZERO);
	sprite->setPosition(Vec2(400, 0));

	Sprite* sprite1 = Sprite::create("men1.jpg");
	Size s = Size(200, 181);
	sprite1->setContentSize(s);
	sprite1->setScale(0.20);
	sprite1->setAnchorPoint(Vec2::ZERO);
	sprite1->setPosition(Vec2(600, 0));

	cell->addChild(sprite);
	cell->addChild(sprite1);
	cell->addChild(label);
	return cell;
}